package com.prb.controller;

import com.prb.pojo.Resume;
import com.prb.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@Controller
@RequestMapping("/resume")
public class ResumeController {

    @Autowired
    ResumeService resumeService;

    @GetMapping("/page")
    public ModelAndView page(ModelAndView mv){

        List<Resume> resumes = listResume();
        mv.addObject("data" , resumes);
        mv.setViewName("resume");

        return mv;
    }

    @GetMapping("/list")
    @ResponseBody
    public List<Resume> listResume(){

        return resumeService.listResume();
    }


    @GetMapping("/upd")
    public void saveResume(Resume resume , HttpServletResponse response) throws IOException {

        resumeService.addResume(resume);
        response.sendRedirect("/resume/page");
    }

    @GetMapping("/del")
    public void delResume(Long resumeId , HttpServletResponse response) throws IOException {

        resumeService.delById(resumeId);
        response.sendRedirect("/resume/page");
    }




}
